package com.study.portal.controller.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.study.portal.util.InitConfig;

public class DefaultFilter implements Filter {

	private Logger logger = Logger.getLogger(this.getClass());

	public void destroy() {
		logger.debug("DefaultFilter 过滤器已销毁...");
	}

	public void doFilter(ServletRequest sRequest, ServletResponse sResponse,
			FilterChain filterChain) throws IOException, ServletException {
		HttpServletResponse response = (HttpServletResponse) sResponse;
		HttpServletRequest request = (HttpServletRequest) sRequest;
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("UTF-8");
		request.setAttribute("request_url", request.getRequestURL());
		filterChain.doFilter(request, response);
	}

	public void init(FilterConfig config) throws ServletException {
		logger.debug("DefaultFilter 过滤器初始化成功...");
		new InitConfig();
	}

}

